package com.nowcoder.community.c_service;

import com.nowcoder.community.a_entity.Message;
import com.nowcoder.community.b_dao.MessageMapper;
import com.nowcoder.community.z_util.MinGanF;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageService {
    //私信的service都是直接抄dao return即可
    @Autowired
    private MessageMapper messageMapper;
    @Autowired
    private MinGanF minGanF;

    public List<Message> findConversations(int userId, int offset, int limit) {
        return messageMapper.selectConversations(userId, offset, limit);
    }

    public int findConversationCount(int userId) {
        return messageMapper.selectConversationCount(userId);
    }

    public List<Message> findLetters(String conversationId, int offset, int limit) {
        return messageMapper.selectLetters(conversationId, offset, limit);
    }

    public int findLetterCount(String conversationId) {
        return messageMapper.selectLetterCount(conversationId);
    }

    public int findLetterUnreadCount(int userId, String conversationId) {
        return messageMapper.selectLetterUnreadCount(userId, conversationId);
    }


    //添加私信（control补了data等信息，还需处理敏感词）
    public void addMessage(Message message){
        message.setContent(minGanF.guolv(message.getContent()));
        //过滤完别忘核心插
        messageMapper.insertMessage(message);
    }


    //更新指定id-list为已读1
    public void readedMessgae(List<Integer> idList){
        messageMapper.updateStatus(idList, 1);
    }


    //系统通知-直
    public Message findLatestNotice(int userId, String topic) {
        return messageMapper.selectLatestNotice(userId, topic);
    }

    public int findNoticeCount(int userId, String topic) {
        return messageMapper.selectNoticeCount(userId, topic);
    }

    public int findNoticeUnreadCount(int userId, String topic) {
        return messageMapper.selectNoticeUnreadCount(userId, topic);
    }

    public List<Message> findNotices(int userId, String topic, int offset, int limit) {
        return messageMapper.selectNotices(userId, topic, offset, limit);
    }

}
